package com.frxuexi.mine.room

import android.content.Context
import androidx.room.Database
import androidx.room.DatabaseConfiguration
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.sqlite.db.SupportSQLiteOpenHelper
import com.frxuexi.mine.entity.User

@Database(entities = [User::class], version = 1)
abstract class AppDataBase:RoomDatabase() {

    abstract fun userDao(): UserDao

    companion object{
        @Volatile
        private var appDataBase: AppDataBase?=null

        fun getInstance(context: Context): AppDataBase = appDataBase ?: synchronized(this){
            appDataBase ?: buildDataBase(context)
        }

        fun buildDataBase(context: Context): AppDataBase {
            return Room.databaseBuilder(context.applicationContext, AppDataBase::class.java,"mdm2201")
                .addMigrations()
                .build()
        }
    }
}